# !/usr/bin/python
# -*- coding: UTF-8 -*-

import calendar

"""
method:get_weekend()
获取当前月的周六

method:get_no_work_day()
获取当前月工作日
"""


def holiday(date):
    holiday_list = ['20210101', '20210102', '20210103', '20210131',
                    '20210211', '20210212', '20210213', '20210214', '20210215', '20210216', '20210217',
                    '20210403', '20210404', '20210405',
                    '20210501', '20210502', '20210503', '20210504', '20210505',
                    '20210612', '20210613', '20210614',
                    '20210919', '20210920', '20210921',
                    '20211001', '20211002', '20211003', '20211004', '20211005', '20211006', '20211007',

                    '20220101', '20220102', '20220103', '20220131',
                    '20220201', '20220202', '20220203', '20220204', '20220205', '20220206',
                    '20220403', '20220404', '20220405', '20220430',
                    '20220501', '20220502', '20220503', '20220504',
                    '20220603', '20220604', '20220605',
                    '20220910', '20220911', '20220912',
                    '20221001', '20221002', '20221003', '20221004', '20221005', '20221006', '20221007',
                    '20230101','20230102', '20230121', '20230122', '20230123','20230124', '20230125',
                    '20230126','20230127',
                    '20230403', '20230404','20230405','20220429', '20220430',
                    '20230501','20230502', '20230503', '20230622', '20230623','20230624',
                    '20230929', '20230930', '20231001', '20231002','20231003', '20231004','20231005','20231006',
                    ]
    return date in holiday_list


def get_weekend(year, month):
    calendar.setfirstweekday(firstweekday=6)
    cal = calendar.month(year, month)
    # print("以下输出%d年%d月份的日历:" % (year, month))
    # print(cal)
    #
    # print("以下输出%d年%d月份所有周六的日期:" % (year, month))
    # print(calendar.monthcalendar(2021, 1))
    Saturady_list = []
    for one_weak in calendar.monthcalendar(year, month):
        # 排除法定假期 && 排除需要补调休的周六
        if one_weak[-1] > 0:
            # 判断当前日期是否是一个月的前10天,是则拼接日期需要补0
            if one_weak[-1] < 10:
                saturday = str(year) + str(month) + '0' + str(one_weak[-1])
            else:
                saturday = str(year) + str(month) + str(one_weak[-1])
            # 不是法定节假日写入list
            if not holiday(saturday):
                Saturady_list.append("%d.%d" % (month, one_weak[-1]))

    print(Saturady_list)
    return Saturady_list


def get_workday(year, month):
    """
    获取当前月的工作日
    :param year:
    :param month:
    :return:
    """
    calendar.setfirstweekday(firstweekday=6)
    cal = calendar.month(year, month)
    # print("以下输出%d年%d月份的日历:" % (year, month))
    # print(cal)
    no_work_day = []
    for one_weak in calendar.monthcalendar(year, month):
        if one_weak[1] > 0:
            no_work_day.append(one_weak[1:6])

    return no_work_day


def get_no_work_day(year, month, nums):
    s = ''
    try:
        ll = get_workday(year, month)
        print("ll:", ll)
        for i in range(int(nums / 5)):
            s += '{}年{}月'.format(year, month)
            s += '{}日至{}日;'.format(ll[i][0], ll[i][4])

        other_day = nums % 5

        if other_day == 1:
            s += '{}年{}月'.format(year, month)
            s += '{}日'.format(ll[int(nums / 5)][0])
        elif other_day == 0:
            s += ''
        else:
            s += '{}年{}月'.format(year, month)
            s += '{}日至{}日;'.format(ll[int(nums / 5)][0],
                                   ll[int(nums / 5)][other_day - 1])
    except BaseException:
        s += 'TODO 工作日不够了QAQ'
        print('数组越界异常')
    return s


if __name__ == '__main__':
    # ll = get_weekend(2021, 12)
    # print(ll[:3])
    #
    # rest_weekend_num = 3
    # print('/'.join(ll[:rest_weekend_num]))
    print('------------------------------------')
    # nums = 3
    # s = get_no_work_day(2021, 12, nums)
    # print(s)

    get_workday(2020,12)
